// 对ajax封装
import axios from 'axios'

// 引入依赖面
import 'nprogress/nprogress.css'
import NProgress from "nprogress";

// 创建实例
const mockAjax = axios.create({
    baseURL: '/mock',
    timeout: 1000,
})

// 请求拦截器
mockAjax.interceptors.request.use(config => {
    NProgress.start()
    return config
})

// 响应拦截器
mockAjax.interceptors.response.use(
    response => {
        NProgress.done()
        return response.data
    },
    err => {
        NProgress.done()
        return Promise.reject(new Error(err.message))
    }
)

export default mockAjax
